package com.analyze.datasource.mgr;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.analyze.datasource.dao.DataSourceDao;
import com.analyze.datasource.dao.DatabaseDriverDao;
import com.analyze.datasource.po.DataSource;
import com.analyze.datasource.po.DatabaseDriver;

@Service
public class DataSourceMgr {
	@Autowired
	DatabaseDriverDao dataBaseDriverDao;
	@Autowired
	DataSourceDao dataSourceDao;
	
	public List<DataSource> getAllDataSource(){
		return dataSourceDao.findAll();
	}
	
	public List<DatabaseDriver> getAllDBDriver(){
		return dataBaseDriverDao.findAll();
	}
	
	public void saveDataSource(DataSource dataSource){
		dataSourceDao.save(dataSource);
	}
	
	public DatabaseDriver getDataBaseDriver(Long id){
		return dataBaseDriverDao.findById(id);
	}

	public DataSource getDataSource(long id) {
		
		return dataSourceDao.findById(id);
	}
	
	public Boolean deleteDataSource(Long id){
		DataSource dataSource = dataSourceDao.findById(id);
		if(dataSource!=null){
			dataSourceDao.remove(dataSource);
			return true;
		}
		return false;
	}
}
